home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 July: Mac OS SDK / Dev.CD Jul 97 SDK1.toast / Development Kits (Disc 1) / QuickDraw GX / Programming Stuff / Sample Code / Graphics Samples / House Picture ƒ / house picture.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-15  |  6.1 KB  |  201 lines  |  [TEXT/KAHL]

  1. /*
  2.     House picture
  3.  
  4.     This application will create a picture of a house.  Each object in the picture will represent one piece of the house.
  5.     The border of the house and the window frames are created with polygons.  The door is created with a rectangle. Each object
  6.     is added to the picture with a call to AddToPicture.  The color of various objects by adding an ink to the object.
  7.     
  8.     NOTES:
  9.     • This file requires the following files to run correctly:
  10.         "graphics shell.c", "ColorLibrary.c", "GraphicsDebugLibrary.c",
  11.         "PictureLibrary.c", "ShapeLibrary.c", "TransformLibrary.c".
  12.         
  13.     • This file prints the "best" in landscape mode.
  14.  
  15.     Change History:
  16.  
  17.        4/96    bob        Updated #includes to support changed GX Library names.
  18.                     Updated the note regarding the files needed to run.
  19.                     Updated the copyright date.
  20.  
  21.     ©1990 - 1996  Apple Computer, Inc.
  22.     All rights reserved.
  23. */
  24.  
  25. #include <Events.h>
  26. #include <FixMath.h>
  27. #include <Windows.h>
  28.  
  29. #include "GraphicsLibraries.h"
  30. #include <GXEnvironment.h>
  31. #include "graphics shell.h"
  32.  
  33.  
  34. //
  35. //  Set up the title and size of the window 
  36. //
  37. Str255         gWindowTitle = "\pHouse Picture";
  38. Rect         gWindowQDRect  = {40, 10, 185, 275};
  39.  
  40.  
  41. //
  42. //    gGraphicsHeapSize sets the size of the graphics heap created by calling the GXNewGraphicsClient routine
  43. //    in main () within graphics shell.c.  You can determine the amount of graphics heap required by using GraphicsBug.
  44. //    With  gGraphicsHeapSize set to 25k, I had 3 free blocks left in the graphics heap. Sounds good to me.
  45. //
  46. long        gGraphicsHeapSize = 25;
  47.  
  48. gxShape     gOurHouse;
  49.  
  50.  
  51.  
  52. /*------ DoInitialization ---------------------------------------------------------------------------------*/
  53.  
  54. void DoInitialization(aWindow)
  55. WindowPtr aWindow;
  56. {
  57.     long         windowGeometry[] = {3, // number of contours 
  58.                                        4, // points in frame
  59.                                        0, 0,  ff(30), 0,  ff(30), ff(30),  0, ff(30), // window frame
  60.                                     2, // points in vertical crossbar 
  61.                                     ff(15), 0, ff(15), ff(30),
  62.                                     2, // points in horizontal crossbar
  63.                                     0, ff(15), ff(30), ff(15)};
  64.  
  65.     long         houseGeometry[] = {    7, // number of points in the house border
  66.                                        0, ff(10),  
  67.                                        0, ff(30),  
  68.                                        ff(100), ff(30),  
  69.                                        ff(100), ff(10),  
  70.                                        0, ff(10),
  71.                                        ff(50), 0,  
  72.                                        ff(100), ff(10)};
  73.     
  74.     gxRectangle     doorGeometry = {ff(45), ff(15), ff(55), ff(30)};
  75.     gxShape         windowShape, houseBorderShape, doorShape;
  76.     gxTransform     newWindowTransform; 
  77.  
  78.     gOurHouse = GXNewShape(gxPictureType);
  79.     
  80.     windowShape = GXNewPolygons((gxPolygons *) windowGeometry);
  81.     houseBorderShape = NewPolygon((gxPolygon *) houseGeometry);
  82.     doorShape = GXNewRectangle(&doorGeometry);
  83.  
  84.     //
  85.     //    Set up the fillType and style for the house border
  86.     // 
  87.     {
  88.         gxStyle thickPen = GXNewStyle();
  89.                 
  90.         GXSetShapeFill(houseBorderShape, gxHollowFill);
  91.         GXSetStylePen(thickPen, ff(1));
  92.     
  93.         AddToPicture(gOurHouse, houseBorderShape, thickPen, nil, nil);
  94.         GXDisposeShape(houseBorderShape);
  95.         GXDisposeStyle(thickPen);
  96.     }
  97.     
  98.     GXSetShapeFill(doorShape, gxHollowFill);
  99.     AddToShape(gOurHouse, doorShape);
  100.     GXDisposeShape(doorShape);
  101.  
  102.     //
  103.     //    We will add the window to our house four times. We move the window within the picture by creating
  104.     //    a new transform each time through the loop. We will also add an ink to each window.
  105.     //
  106.     {    short counter;
  107.     
  108.         GXSetShapeFill(windowShape, gxHollowFill);
  109.  
  110.         for (counter = 2; counter <= 5; counter++)
  111.         {    gxTransform newTransform = GXNewTransform();
  112.         
  113.             GXScaleTransform(newTransform, fixed1/3, fixed1/3, 0, 0);
  114.             if (counter <= 3)
  115.                 GXMoveTransform(newTransform, counter * ff(15) - ff(20), ff(15));
  116.             else
  117.                 GXMoveTransform(newTransform, counter * ff(15) + ff(5), ff(15));
  118.             
  119.             if (counter == 2) 
  120.             {    gxInk redInk = GXNewInk();
  121.                 
  122.                 SetInkCommonColor(redInk, red);  
  123.         
  124.                 AddToPicture(gOurHouse, windowShape, nil, redInk, newTransform);
  125.         
  126.                 GXDisposeInk(redInk);
  127.             } else if (counter == 3)
  128.             {    gxInk grayInk = GXNewInk();
  129.             
  130.                 SetInkCommonColor(grayInk, gxGray);  
  131.                 AddToPicture(gOurHouse, windowShape, nil, grayInk, newTransform);
  132.                 GXDisposeInk(grayInk);
  133.  
  134.             } else 
  135.                 {     gxInk turquoiseInk = GXNewInk();
  136.                         SetInkCommonColor(turquoiseInk, turquoise);  
  137.  
  138.                     AddToPicture(gOurHouse, windowShape, nil, turquoiseInk, newTransform);
  139.                     GXDisposeInk(turquoiseInk);
  140.                 }
  141.                 GXDisposeTransform(newTransform);
  142.         }
  143.         GXDisposeShape(windowShape); 
  144.     }
  145.  
  146.     GXMoveShape(gOurHouse, ff(25), ff(25));
  147.      GXScaleShape(gOurHouse, fl(1.75), fl(1.75),  0, 0); 
  148. }
  149.  
  150.  
  151. /*------ DoDraw ---------------------------------------------------------------------------------------*/
  152.  
  153. void DoDraw(aWindow)
  154. WindowPtr aWindow;
  155. {
  156.     //
  157.     //    I am not exactly sure why GX graphics is posting this notice here, but I did not want to see it. I
  158.     //    think it is a bug... I will look inot this problem before the next CD. Stay tuned to this space for coming details...
  159.     //
  160.     GXIgnoreGraphicsNotice(transform_viewPorts_already_set);
  161.  
  162.     GXDrawShape(gOurHouse);
  163.     
  164.     GXPopGraphicsNotice();
  165. }
  166.  
  167.  
  168. /*------ DoDispose -------------------------------------------------------------------------------------*/
  169.  
  170. void DoDispose(aWindow)
  171. WindowPtr aWindow;
  172. {
  173.     //  
  174.     //    You should always dispose of your GX graphics objects before tossing your window. Why? It's generally good 
  175.     //    form and this approach guarantees that everything is disposed. If you had not disposed of everything, the
  176.     //    call to DisposeWindow should dispose of the objects. If you are running the debugging version of the 
  177.     //    SecretGraphics init with notices set, you will receive a notice that you had not disposed of everything. You
  178.     //    can turn notices on in this file by setting gDebugging = TRUE (above).
  179.     //
  180.     DisposeCommonColors ();
  181.     GXDisposeShape(gOurHouse);
  182.     GXDisposeShape(gWindowBoundsShape);
  183.     DisposeWindow(aWindow);
  184. }
  185.  
  186.  
  187. /*------ DoClick ---------------------------------------------------------------------------------------*/
  188.  
  189. void DoClick( orgMouseLoc, theWindow )
  190. gxPoint        orgMouseLoc;
  191. WindowPtr     theWindow;
  192. {
  193. }
  194.  
  195.  
  196. /*------ DoIdle ----------------------------------------------------------------------------------------*/
  197.  
  198. void DoIdle(aWindow)
  199. WindowPtr aWindow;
  200. {
  201. }